package cn.itcast.timer;

import cn.itcast.dao.system.UserDao;
import cn.itcast.domain.system.User;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class UserBirthdayMsg {
    @Autowired
    private AmqpTemplate amqpTemplate;
    @Autowired
    private UserDao userDao;

    public void sendBirthdayMsg() {
        String birthday = new SimpleDateFormat("MM-dd").format(new Date());
        User user = userDao.findByBirthday(birthday);
        if (user != null){
            Map<String, String> map = new HashMap<>();
            map.put("email",user.getEmail());
            map.put("subject","【SaaS货代云平台】生日祝福");
            map.put("content","年年有今日，岁岁有今朝；恭祝您，恭祝您。生日快乐！");
            amqpTemplate.convertAndSend("email.send",map);
        }
    }
}
